/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fbv.tcc.modelo;

import fbv.tcc.classes.PontoRadiacao;
import fbv.tcc.utils.PropertiesGenerator;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

/**
 *
 * @author Casa
 */
public class ModeloFisico {

    //public ArrayList<Double> radiacaoPositiva = new ArrayList<Double>();
    
    public ModeloFisico() {
    }

    public double calculaRadiacaoET(PontoRadiacao pt) throws FileNotFoundException, IOException {

        Properties res = PropertiesGenerator.carregarProperties();

        double latitudeOficial = Double.parseDouble(res.getProperty("latitudeOficialLocalidade"));
        double latitude = Double.parseDouble(res.getProperty("latitude"));
        double longitude = Double.parseDouble(res.getProperty("longitude"));
        double deslocamento = Double.parseDouble(res.getProperty("deslocamento"));
        int diaJuliano = pt.getTimeStamp().getDayOfYear();

        double tof = pt.toHour();

        double B = Math.toRadians(((diaJuliano - 1) / 365));

        double Emin = 229.2 * (0.000075 + 0.001868 * Math.cos(B) - 0.032077 * Math.sin(B) - 0.014615 * Math.cos(2 * B) - 0.04089 * Math.sin(2 * B));

        double ts = tof + 4 * (latitudeOficial - longitude) + Emin + deslocamento; //inserir delocamento

        double omega = 15 * (12 - ts);

        double delta = 23.45 * Math.sin(Math.toRadians((diaJuliano - 81) / 365));

        double E = 1 + 0.03344 * Math.cos(Math.toRadians(diaJuliano / 365.25)); //Excentricidade da orbita terrestre

        double cosZenit = Math.sin(Math.toRadians(delta)) * Math.sin(Math.toRadians(latitude)) + Math.cos(Math.toRadians(delta)) * Math.cos(Math.toRadians(latitude)) * Math.cos(Math.toRadians(omega));

        double aux = 1365 * E * cosZenit;
        
//        if(aux > 0){
//            radiacaoPositiva.add(aux);
//        }

        return aux;

    }
}
